<?php
/**
 * Created by PhpStorm.
 * User: M2
 * Date: 13-11-11
 * Time: 下午8:03
 */
class YlSearchInputTaglib {

    public function parse($content,$siteid) {
        $matches = preg_parse($content, 'yl:searchInput');
        foreach ($matches as $match) {
            $stylename = getParseOneAttr($match, 'styleName');
            $searchurl = getParseOneAttr($match, 'searchUrl');
            $inputname = getParseOneAttr($match, 'inputName');
            $openwin = getParseOneAttr($match, 'openWin');
            $pagenum = getParseOneAttr($match, 'pageNum');
            $styleName = empty($stylename)?'搜索':$stylename;
            $searchUrl = empty($searchurl)?URL('admin/Search/search'):$searchurl;
            $inputName = empty($inputname)?'word':$inputname;
            $openwin   = empty($openwin)?true:$openwin;
            $pageNum   = empty($pagenum)?20:$pagenum;

            $target = $openwin === 'false'?'_self':'_blank';
            $parseStr = '<form id="form1" action="'.$searchUrl.'" method="post" target="'.$target.'">';
            $parseStr .= '<input type="text" name="'.$inputName.'" id="'.$inputName.'" />';
            $parseStr .= '<input type="hidden" name="pagenum" id="pagenum" value="'.$pageNum.'" />';
            $parseStr .= '<input type="hidden" name="siteid" id="siteid" value="'.$siteid.'" />';
            $parseStr .= '<input type="submit" value="'.$styleName.'" />';
            $parseStr .= '</form>';
            $content = str_replace($match, $parseStr, $content);
        }
        return $content;
    }
}
